﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xunit;
using Configuration.Templating.Scope;

namespace Aricie.LuceneSearch.Tests.Components.Config.Templating
{
    public class TemplateScopingTest
    {

        [Fact]
        public void ICanCreateAllScopes()
        {
            var scopeDefault = new LuceneSearchScope();
            var scope1 = new HostScope();
            var scope2 = new PortalScope(0);
            var scopeModule = new ModuleScope(0, 0);
        }
        
        public class TheRetrieveNamingMethod
        {
            [Fact]
            public void AlwaysReturnACustomFilenameForItsScope()
            {
                var scopeDefault = new LuceneSearchScope();
                Assert.NotNull(scopeDefault.RetrieveNaming());
                Assert.NotEqual(string.Empty, scopeDefault.RetrieveNaming());

                var scopeHost = new HostScope();
                Assert.NotNull(scopeHost.RetrieveNaming());
                Assert.NotEqual(string.Empty, scopeHost.RetrieveNaming());

                var scopePortal = new PortalScope(0);
                Assert.NotNull(scopePortal.RetrieveNaming());
                Assert.NotEqual(string.Empty, scopePortal.RetrieveNaming());
                var scopeAlternatePortal = new PortalScope(1);
                Assert.NotEqual(scopeAlternatePortal.RetrieveNaming(), scopePortal.RetrieveNaming());

                var scopeModule = new ModuleScope(0, 0);
                Assert.NotNull(scopeModule.RetrieveNaming());
                Assert.NotEqual(string.Empty, scopeModule.RetrieveNaming());
                var scopeAlternateModule = new ModuleScope(1, 0);
                Assert.NotEqual(scopeAlternateModule.RetrieveNaming(), scopeModule.RetrieveNaming());
                var scopeAlternateModule2 = new ModuleScope(0, 1);
                Assert.NotEqual(scopeAlternateModule2.RetrieveNaming(), scopeModule.RetrieveNaming());
            }
        }

        public class TheRetrieveParentScopeMethod
        {
            [Fact]
            public void ReturnsAPortalScopeWhenCalledFromAModuleScope()
            {
                var ScopeModule = new ModuleScope(10, 11);
                Assert.Equal(10, ScopeModule.PortalId);
                Assert.Equal(11, ScopeModule.ModuleId);

                var scopeParent = ScopeModule.RetrieveParentScope();
                Assert.IsType<PortalScope>(scopeParent);
                Assert.Equal(10, ((PortalScope)scopeParent).PortalId);
            }

            [Fact]
            public void ReturnsAHostScopeWhenCalledFromAPortalScope()
            {
                var ScopePortal = new PortalScope(10);
                Assert.Equal(10, ScopePortal.PortalId);

                var scopeParent = ScopePortal.RetrieveParentScope();
                Assert.IsType<HostScope>(scopeParent);
            }

            [Fact]
            public void ReturnsALuceneSearchScopeWhenCalledFromAHostScope()
            {
                var Scope = new HostScope();

                var scopeParent = Scope.RetrieveParentScope();
                Assert.IsType<LuceneSearchScope>(scopeParent);
            }

            [Fact]
            public void ReturnsNullWhenCalledFromALuceneSearchScope()
            {
                var Scope = new LuceneSearchScope();

                Assert.Null(Scope.RetrieveParentScope());
            }
        }
    }
}
